# Copyright (c) 2016 Lucky Byte, Inc.
#
express = require 'express'
sysinfo = require 'systeminformation'

router = express.Router()
module.exports = router;


router.get '/', (req, res, next) ->
    # 获取系统版本
    res.locals.version = sysinfo.version()

    # 获取开机时间信息
    res.locals.uptime = sysinfo.time().uptime

    # 获取系统信息
    await sysinfo.system defer data
    res.locals.system = data

    # 获取系统信息
    await sysinfo.osInfo defer data
    res.locals.os_info = data

    # 获取CPU数据信息
    await sysinfo.cpu defer data
    res.locals.cpu = data

    # 获取内存数据
    await sysinfo.mem defer data
    # JSON.stringify()解析后端数据准备传入前端使用
    res.locals.mem = JSON.stringify(data)

    # 获取安装的文件系统的数组
    await sysinfo.fsSize defer data
    res.locals.fs_size = JSON.stringify data

    # 获取CPU Load(CPU负载)
    await sysinfo.currentLoad defer data
    res.locals.cpu_load = JSON.stringify(data)

    # 网络接口,忽略第一个环回接口
    network_stats = []
    await sysinfo.networkInterfaces defer data
    for item,index in data
        if index > 0
            await sysinfo.networkStats item.iface, defer data
            network_stats.push(data)
    res.locals.network_stats = JSON.stringify(network_stats)

    return res.render 'stats'
